//
//  GetiLoLButton.m
//  ImageReplacer
//
//  Created by Tyler Powell on 5/1/12.
//  Copyright 2012 Georgia Institute of Technology. All rights reserved.
//

#import "GetiLoLButton.h"


@implementation GetiLoLButton
@synthesize comboBox;
@synthesize writer;
- (IBAction)openiLoLFile:(id)pId;
{
	NSOpenPanel* openDlg = [NSOpenPanel openPanel];
	//NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
	[openDlg setCanChooseFiles:YES];
	[openDlg setCanChooseDirectories:YES];
    //[openDlg setDirectoryURL:[NSURL fileURLWithPath:[@"file://" stringByAppendingString:[@"~/Applications" stringByExpandingTildeInPath]] isDirectory:YES]];
    //NSLog([[openDlg directoryURL]path]);
    NSArray* fileTypes = [NSArray arrayWithObject:@"app"];
    NSString* fileName = nil;
	if([openDlg runModalForDirectory:nil file:nil types:fileTypes] == NSOKButton)
	{

		NSArray* files = [openDlg filenames];
		for(int i=0; i<[files count]; i++)
		{
			fileName = [files objectAtIndex:i];
			//writeToFileAtIndex(@"options.txt", fileName,0);
            
            [writer addLauncher:fileName];
			//[workspace openFile:fileName];
		}
		
	}
    if(fileName){
        [comboBox setStringValue:fileName];
        [writer replaceOptionAtIndex:0 withOption:fileName];
    }
}
@end
